package com.woniu.dao;

import com.woniu.dto.HotDetailDTO;
import com.woniu.dto.HotListDTO;
import com.woniu.pojo.HotList;
import com.woniu.pojo.HotListDetail;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

public interface HotListMapper {
    int deleteByPrimaryKey(Long id);

    int insert(HotList record);

    int insertSelective(HotList record);

    HotList selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(HotList record);

    int updateByPrimaryKey(HotList record);
@Select("select h.id,h.content,h.initiator,h.role_id,h.start_time,\n" +
        "h.place,h.picture,h.create_time,u.user_name \n" +
        "from hotlist h LEFT JOIN users u on h.initiator=u.id " +
        "where now() <= h.start_time and h.status=1 order by h.create_time desc")
    List<HotListDTO> selectHotList(Integer currentPage, Integer pageSize);

    @Select("select h.id,h.content,h.initiator,h.role_id,h.start_time,\n" +
            "h.place,h.picture,h.create_time,h.number,h.end_time,u.user_name \n" +
            "from hotlist h LEFT JOIN users u on h.initiator=u.id where" +
            " h.id=#{hotId} "
    )
    HotDetailDTO selectHotDetail(@Param("hotId") Long hotId);
@Select("select * from hotlist_detail where hot_id=#{hotId} and user_id=#{userId}")
HotListDetail selectHot(@Param("hotId") Long hotId, @Param("userId") Long userId);
@Select("select count(user_id) from hotlist_detail where hot_id=#{hotId}")
    Integer selectRealNum(Long hotId);
@Select("select number from hotlist where id=#{hotId}")
    Integer selectNumber(Long hotId);
@Select("select start_time from hotlist where id=#{hotId}")
    Date selectHotStartTime(Long hotId);

    List<HotListDTO> selectFriendHot(@Param("list") List<Long> friendsId);
@Select("select start_time from hotlist where id=#{id}")
    Date selectTime(Long id);
    @Select("select end_time from hotlist where id=#{id}")
    Date selectEndTime(Long hotId);
    @Select("select h.id,h.content,h.initiator,h.role_id,h.start_time,\n" +
            "h.place,h.picture,h.create_time,u.user_name \n" +
            "from hotlist h LEFT JOIN users u on h.initiator=u.id " +
            "where now() <= h.start_time and h.status=1 order by h.id desc LIMIT 2")
    List<HotListDTO> selectLastestHot();
}